local waieiInfo={
	BGScale="Off",
	Haishin="Off",
	BGRatio=1.333333,
	BGStart=1.0,
};

function SetwaieiInfo(prm,var)
	if prm=="BGScale" then
		waieiInfo["BGScale"]=var;
	elseif prm=="Haishin" then
		waieiInfo["Haishin"]=var;
	elseif prm=="BGRatio" then
		if var~="" then
			waieiInfo["BGRatio"]=tonumber(var);
		else
			waieiInfo["BGRatio"]=1.333333;
		end;
	elseif prm=="BGStart" then
		waieiInfo["BGStart"]=var;
	end;
end;

function GetwaieiInfo(prm)
	if prm=="BGScale" then
		return waieiInfo["BGScale"];
	elseif prm=="Haishin" then
		return waieiInfo["Haishin"];
	elseif prm=="BGRatio" then
		if var~="" then
			return waieiInfo["BGRatio"];
		else
			return waieiInfo["BGRatio"];
		end;
	elseif prm=="BGStart" then
		return waieiInfo["BGStart"];
	end;
	return nil;
end;

function Actor:scale_or_crop_background()
	local gw = self:GetWidth()
	local gh = self:GetHeight()

	local graphicAspect = gw/gh
	local displayAspect = DISPLAY:GetDisplayWidth()/DISPLAY:GetDisplayHeight()

	local bgs = waieiInfo["BGScale"];
	if not bgs then
		bgs = 'Fit';
	end;
	--[[
	if bgs == 'Cover' or
		math.abs(PREFSMAN:GetPreference("DisplayAspectRatio")-waieiInfo["BGRatio"])<= 0.01 then
		self:scaletocover( -SCREEN_WIDTH/2,-SCREEN_HEIGHT/2,SCREEN_WIDTH/2,SCREEN_HEIGHT/2 );
	else
		self:scaletofit( -SCREEN_WIDTH/2,-SCREEN_HEIGHT/2,SCREEN_WIDTH/2,SCREEN_HEIGHT/2 );
	end;
	self:Center();
	--]]
	if bgs == 'Cover' or
		math.abs(PREFSMAN:GetPreference("DisplayAspectRatio")-waieiInfo["BGRatio"])<= 0.01 then
		self:scaletocover( 0,0,SCREEN_WIDTH,SCREEN_HEIGHT );
	else
		self:scaletofit( 0,0,SCREEN_WIDTH,SCREEN_HEIGHT );
	end;

end;

function ScreenSelectMusic:setupmusicstagemods()
	Trace( "setupmusicstagemods" )
	local pm = GAMESTATE:GetPlayMode()

	if pm == "PlayMode_Battle" or pm == "PlayMode_Rave" then
		local so = GAMESTATE:GetDefaultSongOptions()
		GAMESTATE:SetSongOptions( "ModsLevel_Stage", so )
		MESSAGEMAN:Broadcast( "SongOptionsChanged" )
	elseif GAMESTATE:IsAnExtraStage() then
		if GAMESTATE:GetPreferredSongGroup() == "---Group All---" then
			local song = GAMESTATE:GetCurrentSong()
			GAMESTATE:SetPreferredSongGroup( song:GetGroupName() )
		end

		local bExtra2 = GAMESTATE:IsExtraStage2()
		local style = GAMESTATE:GetCurrentStyle()
		local song, steps = SONGMAN:GetExtraStageInfo( bExtra2, style )
		local po, so
		if bExtra2 then
			po = THEME:GetMetric("SongManager","OMESPlayerModifiers")
			so = THEME:GetMetric("SongManager","OMESStageModifiers")
		else
			po = THEME:GetMetric("SongManager","ExtraStagePlayerModifiers")
			so = THEME:GetMetric("SongManager","ExtraStageStageModifiers")
		end

		local difficulty = steps:GetDifficulty()
		local Reverse = PlayerNumber:Reverse()

		GAMESTATE:SetCurrentSong( song )
		GAMESTATE:SetPreferredSong( song )

		for pn in ivalues(GAMESTATE:GetHumanPlayers()) do
			GAMESTATE:SetCurrentSteps( pn, steps )
--			GAMESTATE:GetPlayerState(pn):SetPlayerOptions( "ModsLevel_Stage", po )
			GAMESTATE:SetPreferredDifficulty( pn, difficulty )
--			MESSAGEMAN:Broadcast( "PlayerOptionsChanged", {PlayerNumber = pn} )
		end

--		GAMESTATE:SetSongOptions( "ModsLevel_Stage", so )
--		MESSAGEMAN:Broadcast( "SongOptionsChanged" )
	end
end;


function ScreenSelectMusic:setupcoursestagemods()
	local mode = GAMESTATE:GetPlayMode()

	if mode == "PlayMode_Oni" then

		local po = "clearall,default"
		-- Let SSMusic set battery.
		-- local so = "failimmediate,battery"
		local so = "failimmediate"
		local Reverse = PlayerNumber:Reverse()

		for pn in ivalues(GAMESTATE:GetHumanPlayers()) do
		local def_mod=GAMESTATE:GetPlayerState(pn):GetPlayerOptionsString('ModsLevel_Preferred');
			if def_mod~="" then
				po=po..","..def_mod.."";
			end;
			GAMESTATE:GetPlayerState(pn):SetPlayerOptions( "ModsLevel_Preferred", po )
			MESSAGEMAN:Broadcast( "PlayerOptionsChanged", {PlayerNumber = pn} )
		end;

		GAMESTATE:SetSongOptions( "ModsLevel_Stage", so )
		MESSAGEMAN:Broadcast( "SongOptionsChanged" )
	end
end;

local function CurGameName()
	return GAMESTATE:GetCurrentGame():GetName()
end

function ComboContinue()
	local Continue = {
		dance = GetUserPref_Theme("UserMinCombo"),
		pump = "TapNoteScore_W3",
		beat = "TapNoteScore_W3",
		kb7 = "TapNoteScore_W3",
		para = "TapNoteScore_W4"
	}
	return Continue[CurGameName()]
end

function ComboMaintain()
	local Maintain = {
		dance = GetUserPref_Theme("UserMinCombo"),
		pump = "TapNoteScore_W4",
		beat = "TapNoteScore_W3",
		kb7 = "TapNoteScore_W3",
		para = "TapNoteScore_W4"
	}
	return Maintain[CurGameName()]
end

function GameCompatibleModes()
	local Modes = {
		dance = "Single,Versus,Double,Solo,Couple",
		pump = "Single,Versus,Double,HalfDouble,Couple,Routine",
		beat = "5Keys,Versus5,7Keys,10Keys,14Keys,Versus7",
		kb7 = "KB7",
		para = "Single",
		maniax = "Single,Versus,Double",
		-- todo: add versus modes for technomotion
		techno = "Single4,Single5,Single8,Double4,Double5,Double8",
		lights = "Single" -- lights shouldn't be playable
	}
	return Modes[CurGameName()]
end

function AllowOptionsMenu()
  if GAMESTATE:IsAnExtraStage() then
    return false
  else
    return true
  end
end

function Actor:LyricCommand(side)
	if true then
		self:visible(false);
		return
	end;
end
